"use strict";
function getWidthLeft(t, o) {
    var e = t.position().left, i = t.width(), n = {left: e, width: i};
    return o ? void $(".b-nav-mobile").stop().animate({left: e, width: i}, 300) : n
}
function login() {
    $("#b-modal-login").modal("show"), setCookie("this_url", window.location.href)
}
function logout() {
    $.post(logoutUrl), setTimeout(function () {
        location.replace(location)
    }, 500)
}
function repassword() {
    $("#b-modal-login").modal("hide"), $("#b-modal-repassword").modal("show"),setCookie("this_url", window.location.href)
}
function avatar(){
    $("#b-modal-avatar").modal("show")
}
function register() {
    $("#b-modal-login").modal("hide"), $("#b-modal-register").modal("show"),setCookie("this_url", window.location.href)
}
function goTop() {
    return $("body,html").animate({scrollTop: 0}, 500), !1
}
function setCookie(t, o, e) {
    if (e) {
        var i = new Date;
        i.setTime(i.getTime() + 24 * e * 60 * 60 * 1e3);
        var n = "; expires=" + i.toGMTString()
    } else var n = "";
    document.cookie = t + "=" + o + n + "; path=/"
}
function getCookie(t) {
    for (var o = t + "=", e = document.cookie.split(";"), i = 0; i < e.length; i++) {
        for (var n = e[i]; " " == n.charAt(0);)n = n.substring(1, n.length);
        if (0 == n.indexOf(o))return n.substring(o.length, n.length)
    }
    return null
}
function deleteCookie(t) {
    setCookie(t, "", -1)
}
function recordId(t, o) {
    return setCookie("cid", 0), setCookie("tid", 0), setCookie("search_word", 0), "index" != t && "/" != t && setCookie(t, o), !0
}


$('#fileupload').fileupload({

    dataType: 'json',
    done:  function(e,json) {
        var data = json.result;
        if (data.status ==0) {
            bootbox.alert(data.msg);
        }else{
            //$('#user-avatar').attr('src', data.avatar + '?r=' + Math.random());
            location.reload();
        }
    }
});
function addProject() {
    $("#b-modal-project").modal("show"), setCookie("this_url", window.location.href)
}

function jumpto(url,tid,province,city,area){

    if(tid!=''){
        url=url+'/tid/'+tid;
    }
    if(province!=''){
        url=url+'/province/'+province;
    }
    if(city!=''){
        url=url+'/city/'+city;
    }
   if(area!=''){
    url=url+'/area/'+area;
    }

    window.location.href=url;
}

$(function () {
    if ("block" == $(".b-nav-mobile").css("display")) {
        var t = getWidthLeft($(".b-nav-active"), !1);
        $(".b-nav-mobile").css({width: t.width, left: t.left})
    }
    $(".b-nav-parent li").hover(function () {
        getWidthLeft($(this), !0)
    }, function () {
        getWidthLeft($(".b-nav-active"), !0)
    }), $(".b-article iframe").width("95%"), $(window).scroll(function (t) {
        $(window).scrollTop() > 200 ? ($(".go-top").show(), $(".go-top").removeClass("animated rotateOut"), $(".go-top").addClass("animated rotateIn")) : ($(".go-top").removeClass("animated rotateIn"), $(".go-top").addClass("animated rotateOut"))
    }), window.innerWidth >= 768 && $(window).scroll(function (t) {
        $(window).scrollTop() > 100 ? $("#b-public-nav").stop().animate({
            "padding-top": "0px",
            "padding-bottom": "0px"
        }, 100) : $("#b-public-nav").stop().animate({"padding-top": "5px", "padding-bottom": "5px"}, 100)
    }), $(".b-page .first,.num,.end").addClass("hidden-xs"), $(".b-page .rows").addClass("hidden-xs"), $(".b-chat-middle").height($(".b-chat").height()), $(".b-arrows-right1,.b-arrows-right2").each(function (t, o) {
        $(o).css("top", $(o).parent(".b-chat-one").height() / 2.5)
    }), $.each($(".js-head-img"), function (t, o) {
        var e = $(o).attr("_src");
        $(o).attr("src", e)
    })

    $("#login").on('submit', function(e) {
        e.preventDefault();

        var email  = $('#l-email').val();
        var password = $('#l-password').val();

        if (email == '') {
            bootbox.alert('邮箱不能为空');
            return false;
        }
        if (password == '') {
            bootbox.alert('密码不能为空');
            return false;
        }


        $.ajax({
            url: "/Home/User/login",
            type: 'POST',
            dataType: 'json',
            data: {email: email, password: password},

            success :function(data) {

                if (data.status ==0) {
                    bootbox.alert(data.info);
                    return false;
                } else {
                    $('#l-email').val('');
                    $('#l-password').val('');
                    $('#b-modal-login').modal('hide');
                    location.reload();
                }

            }
        });

    });

    $("#register").on('submit', function(e) {
        e.preventDefault();

        var email  = $('#r-email').val();
        var username  = $('#r-username').val();
        var password = $('#r-password').val();
        var repassword = $('#r-repassword').val();

        if (email == '') {
            bootbox.alert('邮箱不能为空');
            return false;
        }
        if (username == '') {
            bootbox.alert('昵称不能为空');
            return false;
        }
        if (password == '') {
            bootbox.alert('密码不能为空');
            return false;
        }
        if (repassword == '') {
            bootbox.alert('请再输一遍密码');
            return false;
        }
        if(password!=repassword){
            bootbox.alert('两次输入的密码不一样');
            return false;
        }

        $.ajax({

            url: "/Home/User/register",
            type: 'POST',
            dataType: 'json',
            data: {email: email, username:username,password: password,repassword:repassword},

            success :function(data) {

                if (data.status ==0) {
                    bootbox.alert(data.info);
                    return false;
                } else {
                    $('#r-email').val('');
                    $('#r-username').val('');
                    $('#r-password').val('');
                    $('#b-modal-register').modal('hide');
                    location.reload();
                }

            }
        });

    });

    $("#repassword").on('submit', function(e) {
        e.preventDefault();

        var email  = $('#p-email').val();


        if (email == '') {
            bootbox.alert('邮箱不能为空');
            return false;
        }


        $.ajax({
            url: "/Home/User/repassword",
            type: 'POST',
            dataType: 'json',
            data: {email: email},

            success :function(data) {

                if (data.status ==0) {
                    bootbox.alert(data.info);
                    return false;
                } else {
                    $('#p-email').val('');
                    location.reload();
                }

            }
        });

    });


    $("#logout").on('click', function(e) {
        e.preventDefault();


        $.ajax({
            url: "/Home/User/logout",
            type: 'POST',
            dataType: 'json',
            data: {},

            success :function(data) {

                if (data.status ==0) {
                    bootbox.alert(data.info);
                    return false;
                } else {

                    location.reload();
                }

            }
        });

    });


    $("#newproject").on('click', function(e) {
        e.preventDefault();
        $("#new_project").show();
        $("#projectid").hide();
        $("#fatherlist").show();
    });

    $("#neworg").on('click', function(e) {
        e.preventDefault();
        $("#new_org").show();
        $("#orgid").hide();
        $("#fatherlist").hide();
    });


    $("#reset-password").on('submit', function(e) {
        e.preventDefault();


        var password = $('#password').val();
        var rePassword = $('#repassword').val();
        var token = $('#token').val();

        if (password == '') {
            bootbox.alert('密码不能为空');
            return false;
        }
        if (repassword == '') {
            bootbox.alert('请再输一遍密码');
            return false;
        }



        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/Home/index/resetPassword",
            data: {password:password,rePassword:rePassword,token:token},
            success: function(data){
                if (data.status == 0) {
                    bootbox.alert(data.info);
                    return  false;
                } else {

                    setCookie("this_url", window.location.href);
                }

            }
        })

    });



});

